package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.pojo.Orders;
import com.itheima.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @title: OrdersController
 * @Author 椎名真白
 * @Date: 2022-05-02 15:50
 * @Version 1.0
 */

@Slf4j
@RestController
@RequestMapping("order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("submit")
    public R<String> submit(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("订单提交成功");
    }

    @GetMapping("userPage")
    public R<Page<Orders>> page(Integer page,Integer pageSize){
        Page<Orders> pageInfo = new Page(page, pageSize);
        QueryWrapper<Orders> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("checkout_time");
        ordersService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }
    @GetMapping("page")
    public R<Page<Orders>> backendpage(Integer page,Integer pageSize){
        Page<Orders> pageInfo = new Page(page, pageSize);
        QueryWrapper<Orders> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("checkout_time");
        ordersService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    @PutMapping
    public R<String> order(){
        return R.success("开始配送");
    }

}
